package com.xihu.credit.mapper;

import com.xihu.credit.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Update("UPDATE user SET profile = #{profile} WHERE username = #{username}")
    int updateProfile(@Param("username") String username, @Param("profile") String profile);

    @Select("SELECT * FROM user WHERE username = #{username}")
    User findByUsername(@Param("username") String username);


    @Update("UPDATE user SET password = #{password} WHERE username = #{username}")
    int updatePasswordByUsername(@Param("username") String username, @Param("password") String password);

    @Update("UPDATE user SET password = #{password} WHERE email = #{email}")
    int updatePasswordByEmail(@Param("email") String email, @Param("password") String password);
    // 查询用户名对应的用户信息
    @Select("SELECT * FROM user WHERE email = #{email}")
    User findByEmail(String email);

    @Insert("INSERT INTO user (username, mobile, email, password, profile, register_time) " +
            "VALUES (#{username}, #{mobile}, #{email}, #{password}, #{profile}, #{registerTime})")
    int register(User user);

    @Select("SELECT * FROM user WHERE mobile = #{mobile}")
    User findByMobile(String mobile);

    @Select("SELECT * FROM user WHERE username = #{username}")
    User getUserByUsername(String username);

    // 插入用户信息
    @Insert("INSERT INTO user (username, mobile, email, password, register_time, score, profile, credit_limit) " +
            "VALUES (#{username}, #{mobile}, #{email}, #{password}, #{registerTime}, #{score}, #{profile}, #{creditLimit})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(User user);

    // 更新用户信息
    @Update("UPDATE user SET username = #{username}, mobile = #{mobile}, email = #{email}, " +
            "password = #{password}, score = #{score}, profile = #{profile}, credit_limit = #{creditLimit} " +
            "WHERE id = #{id}")
    int updateUser(User user);

    // 查询用户信息
    @Select("SELECT * FROM user WHERE id = #{id}")
    User getUserById(Long id);
}



